# -*- coding: utf-8 -*-
"""
@Auth ： laichenying
@File ：conftest.py
@IDE ：PyCharm

"""
import json
import hashlib
import time

import pytest
from common.http_requests import HttpRequests
from config.url_config import URLConf


@pytest.fixture(scope='session')
def login_http():
    login_URL = URLConf.TEST_NS_API_URL.value
    login_http = HttpRequests(login_URL)
    return login_http


@pytest.fixture(scope='session')
def http():
    url = URLConf.TEST_OTA_API_URL.value
    http = HttpRequests(url)
    return http


@pytest.fixture(scope='session')
def get_login_params():
    grant_type = 'WEB'
    deviceId = 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) ' \
               'Chrome/103.0.5060.134 Safari/537.36 '
    systemType = 'WEB_OMS'
    loginFrom = 'WEB_OMS'
    userName = 'testlxx'
    userPwd = 'qwer1234'
    return locals()


@pytest.fixture(scope="session")
def get_hash_autherization(login_http, get_login_params):
    """获取hash"""
    uri = '/nservice-api/adminLogin'
    headers = {'Content-Type': 'application/json', 'Connection': 'keep-live'}
    data = {'deviceId': get_login_params.get('deviceId'), 'loginFrom': get_login_params.get('loginFrom'),
            'systemType': get_login_params.get('systemType'), 'userName': get_login_params.get('userName'),
            'userPwd': get_login_params.get('userPwd')}
    response = login_http.post(uri, data=json.dumps(data), headers=headers)
    autherization = response.json()['data']['token']
    user_hash = response.json()['data']['hash']
    return locals()